package vn.vfriends.id.service.impl;

import java.util.*;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.handler.MessageContext;
import vn.vfriends.id.service.AccountService;
import vn.vfriends.payment.ws.AccountWS;
import vn.vfriends.payment.ws.AccountWS_Service;

/**
 *
 * @author chaungoctuan@gmail.com
 */
public class AccountServiceImpl implements AccountService {

    private AccountWS getAccountWS() throws Exception {
        AccountWS_Service service = new AccountWS_Service();
        AccountWS accountWS = service.getAccountWSPort();
        Map<String, Object> requestContext = ((BindingProvider)accountWS).getRequestContext();
        
        Map<String, List<String>> headers = new HashMap<String, List<String>>();
        headers.put("USERNAME", Collections.singletonList("wsuser"));
        headers.put("PASSWORD", Collections.singletonList("wsuser"));
        requestContext.put(MessageContext.HTTP_REQUEST_HEADERS, headers);
        return accountWS;
    }
    
    @Override
    public String resetAccount(Long userId, Long initAmount) throws Exception {
        return getAccountWS().resetAccount(userId, initAmount);
    }

    @Override
    public String generateCif(Long userId, Long initAmount) throws Exception {
        return getAccountWS().generateCIF(userId, initAmount);
    }

    @Override
    public long getBalance(String cif) throws Exception {
        return getAccountWS().getBalance(cif);
    }
}
